package com.zhuiYun.project.api.hotSellingList.service.serviceImpl;/**
 * @author syc
 * @date 2023/4/5 10:55
 */

import com.zhuiYun.project.api.commoditydetail.entity.Commodity;
import com.zhuiYun.project.api.commoditydetail.mapper.CommodityMapper;
import com.zhuiYun.project.api.hotSellingList.entity.CommodityType;
import com.zhuiYun.project.api.hotSellingList.hotDaoMapper.HotDaoMapper;
import com.zhuiYun.project.api.hotSellingList.service.HotService;
import com.zhuiYun.project.common.response.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName hotServiceImpl
 * @Description TODO
 * @Author sgo
 * @Date 2023/4/5 10:55
 **/
@Service
public class HotServiceImpl implements HotService {
    @Autowired
    CommodityMapper commodityMapper;
    @Autowired
    HotDaoMapper hotDaoMapper;
    /**
     * 修改商品
     * @param commodity
     * @return
     */
    @Override
    public int UpdateByCommodityById(Commodity commodity) {
        commodityMapper.updateByPrimaryKeySelective(commodity);
        return 0;
    }
    /**
    * 查询商品热销榜 order by desc排序
     * 查询类型前三的 类型展示在首页
    * @param
    */
    @Override
    public CommonResult CommodityByTypeId()  {
        List<CommodityType> list=new ArrayList<>();
//        //查询类型前三的 类型展示在首页
        List<CommodityType> commodityTypes = hotDaoMapper.HotCommodityTypeBy3();
        int b=0;
        for(int i=0;i<4;i++){
            CommodityType commodityType=new CommodityType();
            List<Commodity> commodity=new ArrayList<>();
//            大类型id
            Integer typeId=commodityTypes.get(i).getId();
            System.out.println("");
            List<Commodity> commodities = hotDaoMapper.QueryByCommodityBylist(typeId);
            System.out.println("commodities::"+commodities);
            if(!commodities.isEmpty()){
//                  查出来的商品存入大类型id中
//                commodityTypes.get(i).setCommodityList(commodities);
                commodityType=commodityTypes.get(i);
                commodityType.setCommodityList(commodities);
                list.add(commodityType);
            }else{
                commodityType=commodityTypes.get(i);
                commodityType.setCommodityList(commodity);
                list.add(commodityType);
                continue;
            }
        }
        return CommonResult.ok(list);
    }
    /**
    * @Author sgo
    * @Description
    * @Date 2023/4/7 9:41
    * @Return com.zhuiYun.project.common.response.CommonResult
    */
    @Override
    public CommonResult HotCommodityTypeBy3() {
        return null;
    }
}
